package com.gitee.wsl.doc.prosemirror.model.node.ext

import com.gitee.wsl.doc.prosemirror.model.fragment.Fragment
import com.gitee.wsl.doc.prosemirror.model.node.Node

fun Node.close(content: Fragment): Node {
    type.checkContent(content)
    return copy(content)
}

fun Node.closeRight(depth: Int):Node {
    val node = this
    if (depth == 0) return node
    val fragment = node.content.replaceChild(node.childCount - 1, node.lastChild!!.closeRight( depth - 1))
    val fill = node.contentMatchAt(node.childCount).fillBefore(Fragment.empty, true)
    return node.copy(fragment.append(fill!!))
}